import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.*;

/**
 * @author eii
 * @sice 2020/11/9
 */
public class Time {

    public static void main(String[] args) {
        LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        LocalDateTime s = today.minus(2, ChronoUnit.DAYS);
        System.out.println(s);
        System.out.println(today);
        if(DayOfWeek.TUESDAY == today.getDayOfWeek()){
            System.out.println(DayOfWeek.TUESDAY);
        }

//        LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
//        String yyyyMMdd = today.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
//        LocalDateTime s = today.minus(1, ChronoUnit.WEEKS).with(TemporalAdjusters.previous(DayOfWeek.SUNDAY));
//        LocalDateTime e = today.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY));
    }


   // 这个日期上一周的周一、周日
    public static void main2(String[] args) {
        LocalDate localDate = LocalDate.now();
        DayOfWeek dayOfWeek = localDate.getDayOfWeek().plus(6);
        DayOfWeek mon = DayOfWeek.MONDAY;
        System.out.println(dayOfWeek.equals(mon));


        System.out.println(localDate);
        System.out.println(localDate.atStartOfDay());

        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime);

        LocalDateTime nextWeek = localDateTime.minus(1, ChronoUnit.WEEKS);
        System.out.println(nextWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)));
        System.out.println(nextWeek.with(TemporalAdjusters.next(DayOfWeek.MONDAY)));

        // 随便虚拟一个日期
        LocalDate now = LocalDate.now().plusDays(10);
        System.out.println("当前日期: " + now + " " + now.getDayOfWeek());
        // 求这个日期上一周的周一、周日
        LocalDate todayOfLastWeek = now.minusDays(7);
        LocalDate monday = todayOfLastWeek.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).plusDays(1);
        LocalDate sunday = todayOfLastWeek.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).minusDays(1);
        System.out.println("当前日期：" + now + " 上一周的周一：" + monday + " " + monday.getDayOfWeek());
        System.out.println("当前日期：" + now + " 上一周的周日：" + sunday + " " + sunday.getDayOfWeek());
        LocalDateTime today_start = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        LocalDateTime today_end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        System.out.println(today_start);
        System.out.println(today_end);


        LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);

        LocalDateTime p = today.minus(1, ChronoUnit.WEEKS);
        LocalDateTime s = p.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY));
        LocalDateTime e = today.with(TemporalAdjusters.previous(DayOfWeek.SUNDAY));
        System.out.println(today);
        System.out.println(p);
        System.out.println(s);
        System.out.println(e);
    }
}
